package com.ruoyi.ui.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ui.domain.UiShopcartitem;
import com.ruoyi.ui.service.IUiShopcartitemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 购物车管理Controller
 * 
 * @author ruoyi
 * @date 2022-09-06
 */
@RestController
@RequestMapping("/shopcartitem")
public class UiShopcartitemController extends BaseController
{
    @Autowired
    private IUiShopcartitemService uiShopcartitemService;

    /**
     * 查询购物车管理列表
     */
    @RequiresPermissions("ui:shopcartitem:list")
    @GetMapping("/list")
    public TableDataInfo list(UiShopcartitem uiShopcartitem)
    {
        startPage();
        List<UiShopcartitem> list = uiShopcartitemService.selectUiShopcartitemList(uiShopcartitem);
        return getDataTable(list);
    }

    /**
     * 导出购物车管理列表
     */
    @RequiresPermissions("ui:shopcartitem:export")
    @Log(title = "购物车管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UiShopcartitem uiShopcartitem)
    {
        List<UiShopcartitem> list = uiShopcartitemService.selectUiShopcartitemList(uiShopcartitem);
        ExcelUtil<UiShopcartitem> util = new ExcelUtil<UiShopcartitem>(UiShopcartitem.class);
        util.exportExcel(response, list, "购物车管理数据");
    }

    /**
     * 获取购物车管理详细信息
     */
    @RequiresPermissions("ui:shopcartitem:query")
    @GetMapping(value = "/{cartitemId}")
    public AjaxResult getInfo(@PathVariable("cartitemId") Long cartitemId)
    {
        return AjaxResult.success(uiShopcartitemService.selectUiShopcartitemByCartitemId(cartitemId));
    }

    /**
     * 新增购物车管理
     */
    @RequiresPermissions("ui:shopcartitem:add")
    @Log(title = "购物车管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UiShopcartitem uiShopcartitem)
    {
        return toAjax(uiShopcartitemService.insertUiShopcartitem(uiShopcartitem));
    }

    /**
     * 修改购物车管理
     */
    @RequiresPermissions("ui:shopcartitem:edit")
    @Log(title = "购物车管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UiShopcartitem uiShopcartitem)
    {
        return toAjax(uiShopcartitemService.updateUiShopcartitem(uiShopcartitem));
    }

    /**
     * 删除购物车管理
     */
    @RequiresPermissions("ui:shopcartitem:remove")
    @Log(title = "购物车管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartitemIds}")
    public AjaxResult remove(@PathVariable Long[] cartitemIds)
    {
        return toAjax(uiShopcartitemService.deleteUiShopcartitemByCartitemIds(cartitemIds));
    }
}
